﻿using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using WMS.ProductcategoryTable;
using WMS.ProductcategoryTable.DTO;
using WMS.PurchaseNoticeDetailTable.DTO;

namespace WMS.Web.Controllers
{
    public class ProductcategoryController : Controller
    {
        private readonly IProductcategoryAppService _productcategoryAppService;

        public ProductcategoryController(IProductcategoryAppService productcategoryAppService)
        {
            _productcategoryAppService = productcategoryAppService;
        }

        /// <summary>
        /// 商品分类显示页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 商品分类显示
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetProductcateInfo(int page, int limit, string? productname)
        {
            var list = await _productcategoryAppService.GetProductcateInfo(page, limit, productname);
            return Json(new { data = list.Queryable, code = 0, count = list.RowCount });
        }
        /// <summary>
        /// 商品分类删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> DeleteProducate(int id)
        {
            var list=await _productcategoryAppService.DeleteProducate(id);
            return Json(new { code = list });
        }



        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Create()
        {
            return View();
        }
        /// <summary>
        /// 商品分类添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> CreateProducate(CreateProductcategoryDTO dto)
        {
            var entity = await _productcategoryAppService.CreateProducate(dto);
            return Json(new { code = entity });
        }



        /// <summary>
        /// 修改页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Edit(int id)
        {
            ViewBag.id = id;
            return View();
        }
        /// <summary>
        /// 根据商品分类的ID获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> FanTianProducategoryInfo(int id)
        {
            var list = await _productcategoryAppService.FanTianProducategoryInfo(id);
            return Json(new { data = list });
        }
        /// <summary>
        /// 商品分类修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> UpdateProducate(UpdateProductcategoryDTO dto)
        {
            var entity = await _productcategoryAppService.UpdateProducate(dto);
            return Json(new { code = entity });
        }
    }
}
